package org.jeecg.modules.act.wx;

import org.jeecg.common.wx.Const;
import org.jeecg.common.wx.DateUtil;
import org.jeecg.modules.act.entity.ActForm;
import org.jeecg.modules.act.service.IActFormService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 定时任务
 */

@RestController
@RequestMapping("/wx/")
public class TimerController {

    @Resource
    private IActFormService formService;

    /**
     * 删除过期数据
     */
    @Scheduled(cron = "0 0 * * * ?")
    @GetMapping("deleteBathOutTimeRecord")
    public void deleteBathOutTimeRecord() {
        //查找所有数据
        List<ActForm> list = formService.list();
        //遍历所有数据
        list.forEach(form -> {
            long creteTime = form.getCreateTime().getTime();
            long localTime = new Date().getTime();
            if (localTime - creteTime > Const.WEEKTIME) {
                formService.removeById(form.getId());
            }
        });
    }
}
